package com.edgclub.edg.uc;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;

import com.edgclub.edg.R;

/**
 * 确定取消的对话框
 * 
 * @author 陈坤彬
 *
 */
public class ExitDialog extends Dialog {

	private Button exit;
	private Button  Cancle;

	private Context context;

	private Dialog dialog;

	private SubmitClickListener onSubmitClickListener;

	private ExitDialog instance;



	public static ExitDialog create(Context context) {
		ExitDialog instance = new ExitDialog(context);
		return instance;

	}

	public ExitDialog(Context context) {
		super(context, R.style.MyAlertDialog);
		init(context);
	}

	private void init(Context context) {
		this.context = context;
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
		lp.width = context.getResources().getDisplayMetrics().widthPixels;
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
				WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
		View contentView = LayoutInflater.from(context).inflate(
				R.layout.layout_exit_dialog, null);
		exit= (Button) contentView.findViewById(R.id.exit);
		Cancle= (Button) contentView.findViewById(R.id.cancel);
		setContentView(contentView, lp);

	}
	public void setExitText(String text){
		if(null!=exit)
			exit.setText(text);
	}public void setCancleText(String text){
		if(null!=Cancle)
			Cancle.setText(text);
	}

	/**
	 * 设置确认的监听
	 */
	public void setSubmitListener(
			final SubmitClickListener onSubmitClickListener) {
		exit.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				if (null != onSubmitClickListener) {
					onSubmitClickListener.submitClick();
				}
			}
		});
	}

	/**
	 * 设置取消的监听
	 */
	public void setCancelListener(
			final CancelClickListener onCancelClickListener) {
		Cancle.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				dismiss();
				if (null != onCancelClickListener) {
					onCancelClickListener.cancelClick();
				}
			}
		});
	}


	public interface SubmitClickListener {
		public void submitClick();

	}

	public interface CancelClickListener {
		public void cancelClick();
	}

}
